package com.thankgod7.jobcenter.utils;

import cn.hutool.core.thread.ThreadFactoryBuilder;
import lombok.experimental.UtilityClass;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * AsyncTaskUtils
 *
 * @author thankgod7
 */
@SuppressWarnings("unused")
@UtilityClass
public class AsyncTaskUtils {

    private static final ThreadFactory NAMED_FACTORY = new ThreadFactoryBuilder().setNamePrefix("线程-").build();

    private static final ThreadPoolExecutor EXECUTOR = new ThreadPoolExecutor(2, 10, 60, TimeUnit.SECONDS, new
            ArrayBlockingQueue<>(10), NAMED_FACTORY, new ThreadPoolExecutor.DiscardPolicy());

    public static void execute(Runnable task) {
        EXECUTOR.execute(task);
    }

    public static void shutdown() {
        EXECUTOR.shutdown();
    }
}